package ar.com.angrymachine.hunter.activities;

import java.awt.Graphics;
import java.awt.Rectangle;

import ar.com.angrymachine.hunter.GraphicStyles;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.HunterResourceManager;
import ar.com.angrymachine.hunter.gameplay.Chest;

public class MeltingChestActivity extends ChestActivity
{
	private int disappearTime;
	private int currentGhostTime = 0;

	public MeltingChestActivity(Chest chest, int disappearTime)
	{
		super(chest);
		this.disappearTime = disappearTime;
	}
	
    public String getDescription()
    {
        if(isCompleted())
        {
            return super.getDescription();
        }
        else
        {
        	return Locale.percentageLabel(Locale.GHOST_CHEST, currentTime, getCompletionTime());
        }
    }
		
    public void update(int delta, boolean action, boolean timeIsRunning)
    {
    	super.update(delta, action, timeIsRunning);
        if(timeIsRunning)
        {
        	currentGhostTime += delta;
            if(currentGhostTime >= disappearTime)
            {
            	currentGhostTime = disappearTime;
            	end(true);
            }
        }
    }

    public void paint(Graphics g, Rectangle activityArea)
    {
        GraphicStyles.paintDefaultActivity(g, this, activityArea, HunterResourceManager.getImage("chest-ghost.png"));
        if(!isCompleted())
        {
        	Rectangle bar = GraphicStyles.getBarArea(activityArea);
            g.setColor(GraphicStyles.disappearBarColor());
            GraphicStyles.paintLabeledBar(g, Locale.MELTING, bar, currentGhostTime, disappearTime);
        }
    }
}
